/** EasyWeb iframe v3.1.7 date:2019-03-08 License By http://easyweb.vip */
layui.define(['layer', 'element', 'admin'], function(r) {
  var $ = layui.jquery;
  var layer = layui.layer;
  var element = layui.element;
  var admin = layui.admin;
  var setter = admin.setter;
  var a = '.layui-layout-admin>.layui-header';
  var m = '.layui-layout-admin>.layui-side>.layui-side-scroll';
  var i = '.layui-layout-admin>.layui-body';
  var l = i + '>.layui-tab';
  var p = i + '>.layui-body-header';
  var h = 'admin-pagetabs';
  var n = 'admin-side-nav';
  var j = {};
  var e = false;
  var f = {
    homeUrl     : undefined,
    mTabPosition: undefined,
    mTabList    : []
  };
  f.loadView = function(y) {
    var u = y.menuName;
    var v = y.menuPath;
    if (!v) {
      return layer.msg('url不能为空', {
        icon: 2,
        anim: 6
      });
    }
    if (setter.pageTabs) {
      var t;
      $(l + '>.layui-tab-title>li').each(function() {
        if ($(this).attr('lay-id') === v) {
          t = true;
          return false;
        }
      });
      if (!t) {
        if ((f.mTabList.length + 1) >= setter.maxTabNum) {
          layer.msg('最多打开' + setter.maxTabNum + '个选项卡', {
            icon: 2,
            anim: 6
          });
          admin.activeNav(f.mTabPosition);
          return;
        }
        e = true;
        element.tabAdd(h, {
          id     : v,
          title  : '<span class="title">' + (u || '') + '</span>',
          content: '<iframe lay-id="' + v + '" src="' + v + '" frameborder="0" class="admin-iframe"></iframe>'
        });
        if (v !== f.homeUrl) {
          f.mTabList.push(y);
        }
        if (setter.cacheTab) {
          admin.putTempData('indexTabs', f.mTabList);
        }
      }
      element.tabChange(h, v);
    } else {
      admin.activeNav(v);
      var s = $(i + '>div>.admin-iframe');
      if (s.length <= 0) {
        var x = '<div class="layui-body-header">';
        x += '      <span class="layui-body-header-title"></span>';
        x += '      <span class="layui-breadcrumb pull-right" lay-filter="admin-body-breadcrumb" style="visibility: visible;"></span>';
        x += '   </div>';
        x += '   <div style="-webkit-overflow-scrolling: touch;">';
        x += '      <iframe lay-id="' + v + '" src="' + v + '" frameborder="0" class="admin-iframe"></iframe>';
        x += '   </div>';
        $(i).html(x);
      } else {
        s.attr('lay-id', v);
        s.attr('src', v);
      }
      $('[lay-filter="admin-body-breadcrumb"]').html(f.getBreadcrumbHtml(v));
      var w = u;
      if (v === f.homeUrl) {
        w = $(u).text() || $(m + ' [lay-href="' + f.homeUrl + '"]').text() || '主页';
      }
      f.setTabTitle(w);
      f.mTabList.splice(0, f.mTabList.length);
      if (v !== f.homeUrl) {
        f.mTabList.push(y);
        f.mTabPosition = v;
      } else {
        f.mTabPosition = undefined;
      } if (setter.cacheTab) {
        admin.putTempData('indexTabs', f.mTabList);
        admin.putTempData('tabPosition', f.mTabPosition);
      }
    } if (admin.getPageWidth() <= 768) {
      admin.flexible(true);
    }
  };
  f.loadHome = function(w) {
    var v = admin.getTempData('indexTabs');
    var u = admin.getTempData('tabPosition');
    f.homeUrl = w.menuPath;
    f.loadView(w);
    if (!setter.pageTabs) {
      admin.activeNav(f.homeUrl);
    }
    if (w.loadSetting === undefined || w.loadSetting) {
      if (setter.cacheTab && v) {
        var s = undefined;
        for (var t = 0; t < v.length; t++) {
          if (setter.pageTabs && !w.onlyLast) {
            f.loadView(v[t]);
          }
          if (v[t].menuPath === u) {
            s = t;
          }
        }
        if (s !== undefined) {
          setTimeout(function() {
            f.loadView(v[s]);
            if (!setter.pageTabs) {
              admin.activeNav(u);
            }
          }, 150);
        }
      }
    }
  };
  f.openTab = function(s) {
    if (window !== top && !admin.isTop() && top.layui && top.layui.index) {
      return top.layui.index.openTab(s);
    }
    if (s.end) {
      j[s.url] = s.end;
    }
    f.loadView({
      menuPath: s.url,
      menuName: s.title
    });
  };
  f.closeTab = function(s) {
    if (window !== top && !admin.isTop() && top.layui && top.layui.index) {
      return top.layui.index.closeTab(s);
    }
    element.tabDelete(h, s);
  };
  f.setTabCache = function(s) {
    if (window !== top && !admin.isTop() && top.layui && top.layui.index) {
      return top.layui.index.setTabCache(s);
    }
    admin.putSetting('cacheTab', s);
    if (s) {
      admin.putTempData('indexTabs', f.mTabList);
      admin.putTempData('tabPosition', f.mTabPosition);
    } else {
      f.clearTabCache();
    }
  };
  f.clearTabCache = function() {
    admin.putTempData('indexTabs', null);
    admin.putTempData('tabPosition', null);
  };
  f.setTabTitle = function(t, s) {
    if (window !== top && !admin.isTop() && top.layui && top.layui.index) {
      return top.layui.index.setTabTitle(t, s);
    }
    if (setter.pageTabs) {
      if (!s) {
        s = $(l + '>.layui-tab-title>li.layui-this').attr('lay-id');
      }
      if (s) {
        $(l + '>.layui-tab-title>li[lay-id="' + s + '"] .title').html(t || '');
      }
    } else {
      if (t) {
        $(p + '>.layui-body-header-title').html(t);
        $(p).addClass('show');
        $(a).css('box-shadow', '0 1px 0 0 rgba(0, 0, 0, .03)');
      } else {
        $(p).removeClass('show');
        admin.util.removeStyle(a, 'box-shadow');
      }
    }
  };
  f.setTabTitleHtml = function(s) {
    if (window !== top && !admin.isTop() && top.layui && top.layui.index) {
      return top.layui.index.setTabTitleHtml(s);
    }
    if (!setter.pageTabs) {
      if (s) {
        $(p).addClass('show');
        $(p).html(s);
      } else {
        $(p).removeClass('show');
      }
    }
  };
  f.getBreadcrumb = function(s) {
    if (!s) {
      s = $(i + '>div>.admin-iframe').attr('lay-id');
    }
    var u = [];
    var t = $(m).find('[lay-href="' + s + '"]');
    if (t) {
      u.push(t.text().replace(/(^\s*)|(\s*$)/g, ''));
    }
    while (true) {
      t = t.parent('dd').parent('dl').prev('a');
      if (t.length === 0) {
        break;
      }
      u.unshift(t.text().replace(/(^\s*)|(\s*$)/g, ''));
    }
    return u;
  };
  f.getBreadcrumbHtml = function(s) {
    var v = f.getBreadcrumb(s);
    var u = (s === f.homeUrl ? '' : ('<a ew-href="' + f.homeUrl + '">首页</a>'));
    for (var t = 0; t < v.length - 1; t++) {
      if (u) {
        u += '<span lay-separator="">/</span>';
      }
      u += ('<a><cite>' + v[t] + '</cite></a>');
    }
    return u;
  };
  var g = '.layui-layout-admin .site-mobile-shade';
  if ($(g).length <= 0) {
    $('.layui-layout-admin').append('<div class="site-mobile-shade"></div>');
  }
  $(g).click(function() {
    admin.flexible(true);
  });
  if (setter.pageTabs && $(l).length === 0) {
    var d = '<div class="layui-tab" lay-allowClose="true" lay-filter="' + h + '">';
    d += '      <ul class="layui-tab-title"></ul>';
    d += '      <div class="layui-tab-content"></div>';
    d += '   </div>';
    d += '   <div class="layui-icon admin-tabs-control layui-icon-prev" ew-event="leftPage"></div>';
    d += '   <div class="layui-icon admin-tabs-control layui-icon-next" ew-event="rightPage"></div>';
    d += '   <div class="layui-icon admin-tabs-control layui-icon-down">';
    d += '      <ul class="layui-nav" lay-filter="admin-pagetabs-nav">';
    d += '         <li class="layui-nav-item" lay-unselect>';
    d += '            <dl class="layui-nav-child layui-anim-fadein">';
    d += '               <dd ew-event="closeThisTabs" lay-unselect><a>关闭当前标签页</a></dd>';
    d += '               <dd ew-event="closeOtherTabs" lay-unselect><a>关闭其它标签页</a></dd>';
    d += '               <dd ew-event="closeAllTabs" lay-unselect><a>关闭全部标签页</a></dd>';
    d += '            </dl>';
    d += '         </li>';
    d += '      </ul>';
    d += '   </div>';
    $(i).html(d);
    element.render('nav', 'admin-pagetabs-nav');
  }
  if (setter.pageTabs && setter.tabAutoRefresh) {
    $(l).attr('lay-autoRefresh', 'true');
  }
  element.on('nav(' + n + ')', function(v) {
    var u = $(v);
    var s = u.attr('lay-href');
    if (s && s !== 'javascript:;') {
      var t = u.attr('ew-title');
      if (!t) {
        t = u.text().replace(/(^\s*)|(\s*$)/g, '');
      }
      f.loadView({
        menuPath: s,
        menuName: t
      });
    }
  });
  element.on('tab(' + h + ')', function() {
    var t = $(this).attr('lay-id');
    f.mTabPosition = (t !== f.homeUrl ? t : undefined);
    if (setter.cacheTab) {
      admin.putTempData('tabPosition', f.mTabPosition);
    }
    admin.activeNav(t);
    admin.rollPage('auto');
    var s = $(l).attr('lay-autoRefresh');
    if (s === 'true' && !e) {
      admin.refresh(t);
    }
    e = false;
  });
  element.on('tabDelete(' + h + ')', function(u) {
    var s = f.mTabList[u.index - 1];
    if (s) {
      var t = s.menuPath;
      f.mTabList.splice(u.index - 1, 1);
      if (setter.cacheTab) {
        admin.putTempData('indexTabs', f.mTabList);
      }
      j[t] && j[t].call();
    }
    if ($(l + '>.layui-tab-title>li.layui-this').length <= 0) {
      $(l + '>.layui-tab-title>li:last').trigger('click');
    }
  });
  $(document).off('click.navMore').on('click.navMore', '[nav-bind]', function() {
    var s = $(this).attr('nav-bind');
    $('ul[lay-filter="' + n + '"]').addClass('layui-hide');
    $('ul[nav-id="' + s + '"]').removeClass('layui-hide');
    $(a + '>.layui-nav .layui-nav-item').removeClass('layui-this');
    $(this).parent('.layui-nav-item').addClass('layui-this');
    if (admin.getPageWidth() <= 768) {
      admin.flexible(false);
    }
  });
  if (setter.openTabCtxMenu && setter.pageTabs) {
    layui.use('contextMenu', function() {
      var s = layui.contextMenu;
      if (!s) {
        return;
      }
      $(l + '>.layui-tab-title').off('contextmenu.tab').on('contextmenu.tab', 'li', function(u) {
        var t = $(this).attr('lay-id');
        s.show([{
          icon : 'layui-icon layui-icon-refresh',
          name : '刷新当前',
          click: function() {
            element.tabChange(h, t);
            var v = $(l).attr('lay-autoRefresh');
            if (!v || v !== 'true') {
              admin.refresh(t);
            }
          }
        }, {
          icon : 'layui-icon layui-icon-close-fill ctx-ic-lg',
          name : '关闭当前',
          click: function() {
            admin.closeThisTabs(t);
          }
        }, {
          icon : 'layui-icon layui-icon-unlink',
          name : '关闭其他',
          click: function() {
            admin.closeOtherTabs(t);
          }
        }, {
          icon : 'layui-icon layui-icon-close ctx-ic-lg',
          name : '关闭全部',
          click: function() {
            admin.closeAllTabs();
          }
        }], u.clientX, u.clientY);
        return false;
      });
    });
  }
  r('index', f);
});
